package chapter10;

import java.util.Scanner;

public class TestClass {

	public static void main(String[] args) {
		//operationAccount();
		//testTax();
		printTaxTable();
		
	}
	
	public static void printTaxTable(){
		/*解答 编程题10.8*/
		int[][] breackets2001 = {
				{27050, 65550, 136750, 297350},
				{45200, 109250, 166500, 297350},
				{22600, 54625, 83250, 148675},
				{36250, 93650, 151650, 297350}	
		};
		int[][] breackets2009 = {
				{8350, 33950, 82250, 171550, 372950},
				{16700, 67900, 137050, 20885, 372950},
				{8350, 33950, 68525, 104425, 186475},
				{11950, 45500, 117450, 190200, 372950}
		};
		
		double[] rates2001 = {0.15, 0.275, 0.305, 0.355, 0.391};
		double[] rates2009 = {0.10, 0.15, 0.25,  0.28, 0.33, 0.35};
		
		Tax single = new Tax(Tax.SINGLE_FILER,breackets2001,rates2001,50000);
		Tax marriedJointly = new Tax(Tax.MARRIED_JOINTLY,breackets2001,rates2001,50000);
		Tax marriedSparately = new Tax(Tax.MARRIED_SEPARATELY,breackets2001,rates2001,50000);
		Tax household = new Tax(Tax.HEAD_OF_HOUSEHOLD,breackets2001,rates2001,50000);
		System.out.println("                     -----2001-----                               ");
		System.out.println("Income    single     marriedJointly   marriedSparately   household");
		for(int i = 50000; i <= 60000 ; i += 1000){
			single.setTaxableIncome(i);
			marriedJointly.setTaxableIncome(i);
			marriedSparately.setTaxableIncome(i);
			household.setTaxableIncome(i);
			System.out.printf("%-10d%-11.2f%-17.2f%-19.2f%-2.2f\n",i,single.getTax(),marriedJointly.getTax(),marriedSparately.getTax(),household.getTax());	
		}
		
		single.setBreackets(breackets2009);
		marriedJointly.setBreackets(breackets2009);
		marriedSparately.setBreackets(breackets2009);
		household.setBreackets(breackets2009);
		
		single.setRates(rates2009);
		marriedJointly.setRates(rates2009);
		marriedSparately.setRates(rates2009);
		household.setRates(rates2009);
		
		System.out.println("                     -----2009-----                               ");
		System.out.println("Income    single     marriedJointly   marriedSparately   household");
		for(int i = 50000; i <= 60000 ; i += 1000){
			single.setTaxableIncome(i);
			marriedJointly.setTaxableIncome(i);
			marriedSparately.setTaxableIncome(i);
			household.setTaxableIncome(i);
			System.out.printf("%-10d%-11.2f%-17.2f%-19.2f%-2.2f\n",i,single.getTax(),marriedJointly.getTax(),marriedSparately.getTax(),household.getTax());	
		}
	}
	
	public static void testTax(){
		/*测试Tax类*/
		int[][] breackets2001 = {
				{27050, 65550, 136750, 297350},
				{45200, 109250, 166500, 297350},
				{22600, 54625, 83250, 148675},
				{36250, 93650, 151650, 297350}	
		};
		int[][] breackets2009 = {
				{8350, 33950, 82250, 171550, 372950},
				{16700, 67900, 137050, 20885, 372950},
				{8350, 33950, 68525, 104425, 186475},
				{11950, 45500, 117450, 190200, 372950}
		};
		
		double[] rates2001 = {0.15, 0.275, 0.305, 0.355, 0.391};
		double[] rates2009 = {0.10, 0.15, 0.25,  0.28, 0.33, 0.35};
		double tax;
		
		Tax men3_6 = new Tax(0,breackets2009,rates2009,10000); 
		tax = men3_6.getTax();
		System.out.println("Tax is " + tax);
		
	}
	
 	public static void testTime(){
		/*测试Time类*/
		Time time00 = new Time();
		Time time01 = new Time(555550000);
		Time time02 = new Time(3,3,3);
		
		System.out.printf("Time of GMT is %d:%d:%d\n",time00.getHours(),time00.getMinutes(),time00.getSeconds());		
		System.out.printf("Time of GMT is %d:%d:%d\n",time01.getHours(),time01.getMinutes(),time01.getSeconds());
		System.out.printf("Time of GMT is %d:%d:%d\n",time02.getHours(),time02.getMinutes(),time02.getSeconds());
	}
 	

	public static void testAccount(){
		/*测试Account类*/
		Account account00 = new Account(1122,20000,4.5);
		System.out.println(account00.getDateCreated().toString());
		System.out.printf("Id:%4d\tBalance:%6.2f\tAnnual Interest Rate:%6.2f\n",account00.getId(),account00.getBalance(),account00.getAnnualInterestRate());
		account00.withDraw(2500);
		System.out.printf("Id:%4d\tBalance:%6.2f\tAnnual Interest Rate:%6.2f\n",account00.getId(),account00.getBalance(),account00.getAnnualInterestRate());
		account00.deposit(3000);
		System.out.printf("Id:%4d\tBalance:%6.2f\tAnnual Interest Rate:%6.2f\n",account00.getId(),account00.getBalance(),account00.getAnnualInterestRate());
	}
	
	public static void operationAccount(){
		/*编程题10.7，使用Account类模拟ATM机*/
		Account[] accArr = new Account[10];
		boolean switchOn = true;
		for (int i =0; i < 10; i++){
			accArr[i] = new Account(i,100.0,4.5);
		}
		Scanner input = new Scanner(System.in);
		System.out.print("Enter an id:");
		while(switchOn){		
			int id, choice;
			id = input.nextInt();
			System.out.println(" ");
			if (id >= 0 && id < 10){
				printMenu();
				choice = input.nextInt();
				while(choice != 4){
					processChoice(choice, accArr[id]);
					printMenu();
					choice = input.nextInt();
					if (choice == 4){
						System.out.println(" ");
					}
					
				}
				System.out.print("Enter an id:");
			}
			else{
				System.out.println("The ID entered is incorrect. Please re-enter it.");
				System.out.print("Enter an id:");
			}
		}
		
	}
	
	public static void printMenu(){
		/*打印主菜单*/
		System.out.println("Main menu:");
		System.out.println("1: check blance");
		System.out.println("2: withdraw");
		System.out.println("3: deposite");
		System.out.println("4: exit");
		System.out.print("Enter a choice:");
	}
	

	public static void processChoice(int choice,Account user){
		/*处理选项*/
		Scanner input = new Scanner(System.in);
		double amount;
		switch (choice){
			case 1:
				System.out.printf("The balance is %.1f\n",user.getBalance());
				System.out.println(" ");
				return;
			case 2:
				System.out.print("Enter an amount to withdraw:");
				amount = input.nextDouble();
				System.out.println(" ");
				user.withDraw(amount);
				return;
			case 3:
				System.out.print("Enter an amount to deposit:");
				amount = input.nextDouble();
				System.out.println(" ");
				user.deposit(amount);
				return;
			default:return;
		}

	}
	
	
}


